package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.dao.Functiondao;
import com.zr.model.User;
import com.zr.service.FunctionService;

import net.sf.json.JSONArray;

public class FunctionActionSCM extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware{

	private HttpServletRequest req;
	private HttpServletResponse resp;
	private Map<String, Object> session;
	
	
	//属性注入
	@Resource
	private  FunctionService functionService;
	public void functionsShow(){
		try {
			req.setCharacterEncoding("utf-8");
			resp.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		User u=(User) session.get("user");
		
		int pid=-1;
		
		JSONArray j=functionService.getfunctions(pid, u.getRole().getFid());
		
		PrintWriter pw;
		try {
			pw = resp.getWriter();
			pw.write(j.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
	}
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return super.execute();
	}
	
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.resp=arg0;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.req=arg0;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session=arg0;
	}

}
